﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace _20170202_GameNode
{
    class Drawer
    {
        private readonly char gameNodeSymbol;
        private readonly char frameChar;

        public Drawer (char gameNodeChar, char frameChar)
        {
            gameNodeSymbol = gameNodeChar;
            this.frameChar = frameChar;
        }

        public void DrawNode(GameNode node, ConsoleColor color)
        {
            DrawGameNode(node, color);
            ClearGameNode(node);
        }
        
        private void DrawGameNode(GameNode node, ConsoleColor color)
        {
            Console.ForegroundColor = color;
            Console.SetCursorPosition(node.X, node.Y);
            Console.Write(gameNodeSymbol);
            Thread.Sleep(200);
            Console.ForegroundColor = ConsoleColor.White;
        }

        private void ClearGameNode(GameNode node)
        {
            Console.SetCursorPosition(node.X, node.Y);
            Console.Write(' ');
        }

        public void DrawGameFieldFrame(GameField field)
        {
            int yPosition = field.StartY - 1;
            int xPosition = field.StartX - 1;

            for(int i = 0; i < field.Height+2; i++)
            {
                Console.SetCursorPosition(xPosition, yPosition);
                for (int j = 0; j < field.Width+2; j++)
                {
                    if (i==0 || i == field.Height +1)
                    {
                        Console.Write(frameChar);
                    }
                    else if (j==0 || j == field.Height+1)
                    {
                        Console.Write(frameChar);
                    }
                    else
                    {
                        Console.Write(' ');
                    }
                }
                Console.WriteLine();
                Console.SetCursorPosition(field.StartX, ++yPosition);
            }
        }
    }
}
